package com.freedy.concurrent.Monitors.reentrantLock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 可重入
 * @author Freedy
 * @date 2021/4/22 20:11
 */
@Slf4j
public class Test1 {
    private static final ReentrantLock lock=new ReentrantLock();
    public static void main(String[] args){
        lock.lock();
        try{
            m1();
        }finally {
            lock.unlock();
        }
    }
    public static void m1(){
        lock.lock();
        try{
            m2();
        }finally {
            lock.unlock();
        }
    }

    public static void m2(){
        lock.lock();
        try{
            log.info("进入m2");
        }finally {
            lock.unlock();
        }
    }
}
